import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { CrossDefenceRewardItemRender } from "../crossDefenceCopy/item/CrossDefenceRewardItemRender";
import { RadioButtonGroup } from "../../../../../fl/controls/RadioButtonGroup";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Cache } from "../../../cache/Cache";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { MsgManager } from "../../../manager/MsgManager";
import { GRadioButton } from "../../../../../com/mui/controls/GRadioButton";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { CopyConfig } from "../../../resource/CopyConfig";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
type int = number;
//class SelectCopyDropTimeView
    
    export  class SelectCopyDropTimeView extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(300, 380);
            titleHeight = 26;
            title = Language.getString(27606);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(20, 40, 260, 325, this);
            var loc1=ObjCreate.createTextField(Language.getString(27607), 43, 55, 200, 20, this, GlobalStyle.textFormat6);
            this._rewards = ObjCreate.createTileList(35, 78, 230, 120, this);
            this._rewards.scrollPolicy = ScrollPolicy.OFF;
            this._rewards.columnWidth = 41;
            this._rewards.rowHeight = 41;
            this._rewards.setStyle("cellRenderer", CrossDefenceRewardItemRender);
            var loc2=ObjCreate.createTextField(Language.getString(27608), 43, 206, 200, 20, this, GlobalStyle.textFormat6);
            this._multipleSp = new Object /* flash.display.Sprite */();
            this._multipleSp.x = 75;
            this._multipleSp.y = 227;
            this.addChild(this._multipleSp);
            this._radioGroup = new RadioButtonGroup("main");
            this._radioGroup.addEventListener(flash.events.Event.CHANGE, this.selectItem);
            this._getRewardBtn = ObjCreate.createGButton(Language.getString(27605), 104, 320, 90, 28, this, "ButtonRed");
            this._getRewardBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetRewardHandler);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            return;
        }

        /* internal  */onReturnCopyHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal  */onGetRewardHandler(arg1: Object /* flash.events.MouseEvent */=null): void
        {
            var loc1=(this._radioGroup.selectedData as int) + 1;
            Dispatcher.dispatchEvent(new DataEvent(EventName.GetCopyMultiplicityReward, {"times": loc1}));
            return;
        }

        /* internal  */selectItem(arg1: Object /* flash.events.Event */): void
        {
            var loc3=null;
            var loc1=Cache.instance.role.money.gold;
            var loc2=int(this._radioGroup.selectedData);
            if (loc2 > 0) 
            {
                if ((loc3 = this._multipleSp.getChildByName(this.SPENDTEXT_NAME + loc2) as GTextFiled) && loc1 < int(loc3.text)) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(27600));
                    this._radioGroup.selection = this._multipleSp.getChildByName(this.RADIOBTN_NAME + 0) as GRadioButton;
                }
            }
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose();
            if (this._rewards) 
            {
                this.removeChild(this._rewards);
                this._rewards = null;
            }
            if (this._getRewardBtn) 
            {
                this._getRewardBtn.removeEventListener(flash.events.MouseEvent.CLICK, this.onGetRewardHandler);
                this.removeChild(this._getRewardBtn);
                this._getRewardBtn = null;
            }
            if (this._returnBtn) 
            {
                if (this._returnBtn.parent) 
                {
                    this.removeChild(this._returnBtn);
                }
                this._returnBtn.removeEventListener(flash.events.MouseEvent.CLICK, this.onReturnCopyHandler);
                this._returnBtn = null;
            }
            this.hide();
            return;
        }

        public setTitle(arg1: string): void
        {
            this.title = arg1;
            return;
        }

        public itemData(arg1: Array<any>): void
        {
            if (this._rewards) 
            {
                this._rewards.dataProvider = new DataProvider(arg1);
                this._rewards.drawNow();
            }
            return;
        }

        public set multipleOptions(arg1: Array<any>)
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=0;
            var loc8=null;
            if (this._multipleSp.numChildren <= 0) 
            {
                loc1 = 0;
                loc2 = arg1.length;
                while (loc1 < loc2) 
                {
                    loc3 = arg1[loc1];
                    (loc4 = ObjCreate.createRadioButton(loc3[0], 0, loc1 * 25, 100, 28, this._multipleSp, "GCheckBox")).value = loc1;
                    loc4.name = this.RADIOBTN_NAME + loc1;
                    loc4.group = this._radioGroup;
                    if (loc1 == 0) 
                    {
                        loc4.selected = true;
                    }
                    if (int(loc3[1]) != 0) 
                    {
                        loc7 = (loc6 = Cache.instance.copy).isInKingCopy() ? CopyConfig.instance.getExtraDropCost(loc6.copyInfo.code) : loc3[1];
                        loc5 = ObjCreate.createGTextField(String(loc7), 98, 5 + 25 * loc1, 80, 20, this._multipleSp, GlobalStyle.textFormat6);
                        loc8 = GlobalClass.getBitmap("Yuanbao");
                        ObjCreate.setObjAttri(loc8, 120, 5 + 25 * loc1, -1, -1, this._multipleSp);
                    }
                    else 
                    {
                        loc5 = ObjCreate.createGTextField(Language.getString(90324), 98, 5, 80, 20, this._multipleSp, GlobalStyle.textFormat6);
                    }
                    loc5.name = this.SPENDTEXT_NAME + loc1;
                    ++loc1;
                }
            }
            return;
        }

        public showReturnBtn(arg1: Boolean): void
        {
            if (arg1) 
            {
                if (this._returnBtn == null) 
                {
                    this._returnBtn = ObjCreate.createGButton(Language.getString(27612), 160, 320, 90, 28, null, "ButtonRed");
                    this._returnBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onReturnCopyHandler);
                }
                this._getRewardBtn.x = 50;
                this.addChild(this._returnBtn);
            }
            else 
            {
                if (this._returnBtn && this._returnBtn.parent) 
                {
                    this.removeChild(this._returnBtn);
                }
                this._getRewardBtn.x = 104;
            }
            return;
        }

        /* internal */ /* const */RADIOBTN_NAME: string="radioBtn_";

        /* internal */ /* const */SPENDTEXT_NAME: string="spendText_";

        /* internal */ /* var */_radioGroup: RadioButtonGroup;

        /* internal */ /* var */_getRewardBtn: GButton;

        /* internal */ /* var */_returnBtn: GButton;

        /* internal */ /* var */_rewards: GTileList;

        /* internal */ /* var */_multipleSp: Object /* flash.display.Sprite */;
    }
